//
//  VCMember.swift
//  AirlineReservation
//
//  Created by Kevin on 2020/2/19.
//  Copyright © 2020 Kevin. All rights reserved.
//

import UIKit

class VCMember: VCBase {
    
    private lazy var memberView: MemberView = {
        let ui = MemberView()
        let uiY = realHeight + MARGIN10
        ui.frame = CGRect(x: 0, y: uiY, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - uiY)
        ui.backgroundColor = UIColor.white
        return ui
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        init_view()
        init_data()
        init_event()
    }
}

extension VCMember {
    
    private func init_event() -> Void {
        memberView.complete = {item in
            let vc = VCWeb()
            vc.pageapi = "member/\(item)"
            self.pushNextVcHideBottomBar(vc: vc)
        }
    }
    
    private func init_data() -> Void {
        // 请求
        self.doPost(api: "search/memberzone", dict: NSDictionary()) { (dict) in
            if self.isServerSuccess(dict: dict) != 1200 {
                return
            }
            // 解析数据
            guard let zones = dict.value(forKey: SP_BODYREQUEST) as? NSArray else {
                return
            }
            // 会员专享
            var temp = [MemberZoneInfo]()
            for item in zones {
                let zone = MemberZoneInfo(dict: item as! [String : Any])
                temp.append(zone)
            }
            self.memberView.memberZones = temp
        }
    }
    
    private func init_view() -> Void {
        view.addSubview(backroundWhite)
        view.addSubview(memberView)
    }
}
